package com.vrsys.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.vrsys.domain.Coupons4Account;
import com.vrsys.domain.session.Account;
import com.vrsys.persistence.AccountMapper;

@Service
public class AccountService extends BaseService {
    @Autowired
    private AccountMapper accountMapper;

    public List<Account> getAccounts() throws Exception{
       List<Account> accounts = accountMapper.getUsers();
       if(null == accounts)
           accounts = new ArrayList<Account>(1);
       return accounts;
    }

    public Account queryAccount(Account account) {
        return accountMapper.getAccountByweChatId(account.getWeChatId());
    }

    public boolean authAccount(Account account) {
        if(accountMapper.authAccount(account)) {
            return true;
        } else
            return false;
    }

    @Transactional(isolation=Isolation.READ_COMMITTED, rollbackFor=Throwable.class)
    public void addAccount(Account account) {
        accountMapper.addAccount(account);
    }

    @Transactional(isolation=Isolation.READ_COMMITTED, rollbackFor=Throwable.class)
    public void addCoupons(List<Coupons4Account> cpas) {
    }
}
